<template>
  <div class="count">
    <h2>当前求和为：{{sum}} ， 10倍后:{{bigSum}}</h2>
    <div class="desc">作者：{{upperAuthor}}，版本：{{version}}</div>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment">+</button>
    <button @click="decrement">-</button>
    <button @click="incrementOdd">当前求和为奇数再+</button>
    <button @click="incrementWait">等一等+</button>
    <button @click="incrementServer">问一问服务器加几</button>
  </div>
</template>

<script>
  import {mapState,mapGetters} from 'vuex'

  export default {
    name:'Count',
    data() {
      return {
        n:1
      }
    },
    computed:{
      ...mapState(['sum','version']),
      
      /* ******************************** */
      /* bigSum(){
        return this.$store.getters.bigSum
      },
      upperAuthor(){
        return this.$store.getters.upperAuthor
      }, */
      // ...mapGetters({bigSum:'bigSum',upperAuthor:'upperAuthor'})
      ...mapGetters(['bigSum','upperAuthor'])
    },
    methods: {
      increment(){
        this.$store.commit('JIA',this.n)
      },
      decrement(){
        this.$store.commit('JIAN',this.n)
      },
      incrementOdd(){
        this.$store.dispatch('jishuJia',this.n)
      },
      incrementWait(){
        this.$store.dispatch('dengJia',this.n)
      },
      incrementServer(){
        this.$store.dispatch('fuwuJia')
      }
    }
  }
</script>

<style scoped>
  .count {
    background-color: skyblue;
    padding: 20px;
  }
  button {
    margin-left: 10px;
  }
  .desc {
    margin-bottom: 20px;
  }
</style>